//
//  uiNode.hpp
//  smu_test1
//
//  Created by jiayi on 16/9/26.
//
//

#ifndef uiNode_hpp
#define uiNode_hpp

#include "uiCommon.hpp"
#include "base/CCEvent.h"
#include "base/CCTouch.h"
USING_NS_CC;

class smuNode;
class Layer;
class uiNodeLine;
// represent a node displayed on the screen
class uiNode : public cocos2d::ui::Widget
{
    uiCreateInit( uiNode );

public:
    friend class uiNodeLine;
    typedef std::vector<uiNode*> uiNodes;
    typedef uiNodes::iterator uiNodesIter;
    typedef uiNodes::const_iterator uiNodesConstIter;
    
public:
    virtual ~uiNode();
    
    // initialization
    virtual bool init() override;
    
    // set/get data
    void setNodeData( smuNode* data );
    smuNode* getNodeData() { return _nodeData; }
    const smuNode* getNodeData() const { return _nodeData; }
    
    // update
    void updateData( int type );
    
    // bind layer
    void bind( cocos2d::Node* layer );
    
    // handle event
    void eventProcessor(Ref*, Widget::TouchEventType);
    
    // add from and rely nodes
    void addFromAndRely( uiNode* node );
    
    // update position
    void updatePosition();
    void updateReliesPosition();
    
    const cocos2d::Size& getVirtualSize() const;
    
    void setDirty( bool d ) { _dirty = d ; }
    
    void setFake( bool f ){ _fake = f; }
    bool isFake() const { return _fake; }
    
    
protected:    
    // update virtual size
    void _updateVirtualSize();
    
protected:
    smuNode* _nodeData;
    uiNodes _relyFrom;
    uiNodes _relyTo;
    cocos2d::Size _virualSize;
    Vec2 _offset;
    Vec2 _startOffset;
    cocos2d::ui::Scale9Sprite* _bg;
    cocos2d::Label* _label;
    
    // double click checker
    uiDoubleClickChecker* _clickChecker;
    
    // target position
    Vec2 _targetPosition;
    
    // line
    uiNodeLine* _line;
    
    // is fake
    bool _fake;
    
    // move parameters
    bool _moving;
    
    // dirty
    bool _dirty;
};

#endif /* uiNode_hpp */
